/**
 * 29/nov/2011 - fabio.melillo@gmail.com
 */
package org.unisannio.util;

import it.unipr.ce.dsg.s2p.sip.Address;

import java.util.ArrayList;

/**
 * The description of the service(s) that the device want to publish
 * 
 * @author Fabio Melillo
 *
 */
public class ServiceInfo {
	
	private String mac;
	private String ip;
	private String port;
	private Address address;
	private ArrayList<ServiceDescriptor> descriptors;
	/**
	 * Type of ServiceDescriptor
	 */
	public static String CONTENT_PROVIDER="content_pub";
	/**
	 * Type of ServiceDescriptor
	 */
	public static String BROADCAST_RECEIVER="broadcast_pub";
	/**
	 * Type of ServiceDescriptor
	 */
	public static String REMOTE_ACTIVITY="activity_pub";
	/**
	 * Used for new peers added to the network
	 */
	public static String NEWTAG=" _newPeerToContact";
	
	public ServiceInfo(){
		descriptors=new ArrayList<ServiceInfo.ServiceDescriptor>();
	}
	
	public ServiceInfo(String mac, String ip, String port) {
		this.mac=mac;
		this.ip=ip;
		this.port=port;
		int portnum=Integer.parseInt(port);
		this.address=new Address(mac, ip, portnum);
		descriptors=new ArrayList<ServiceInfo.ServiceDescriptor>();
	}

	public String getMac() {
		return mac;
	}

	public void setMac(String mac) {
		this.mac = mac;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public Address getAddress() {
		return address;
	}

	public ArrayList<ServiceDescriptor> getDescriptors() {
		return descriptors;
	}
	/**
	 * 
	 * @param uri - of the service [mandatory]
	 * @param tags - for better seeking [optional]
	 * @param schema - for better seeking [optional]
	 * @param type - type of service, broadcast or content [mandatory]
	 * @return the number of ServiceDescriptors for this device
	 */
	public int addDescriptor(String uri, String tags, String schema, String type){
		this.descriptors.add(new ServiceDescriptor(uri, tags, schema, type));
		return this.descriptors.size();
	}

	



	public class ServiceDescriptor {
		
		private String uri;
		private String tags;
		private String schema;
		private String type;
		
		public ServiceDescriptor(String uri, String tags, String schema,
				String type) {
			super();
			this.uri = uri;
			this.tags = tags;
			this.schema = schema;
			this.type = type;
		}
		
		
		public String getUri() {
			return uri;
		}
		public void setUri(String uri) {
			this.uri = uri;
		}
		public String getTags() {
			return tags;
		}
		public void setTags(String tags) {
			this.tags = tags;
		}
		public String getSchema() {
			return schema;
		}
		public void setSchema(String schema) {
			this.schema = schema;
		}
		public String getType() {
			return type;
		}
		public void setType(String type) {
			this.type = type;
		}
		
		
	}
}
